package com.midea.ai.air.ui.more;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.common.ActionBarBackFragment;
import com.midea.ai.air.common.BaseActivity;
import com.midea.ai.air.common.Constant;
import com.midea.ai.air.ui.more.adapter.MoreMyMessageAdapter;
import com.midea.ai.air.ui.more.data.MoreMyMessageItem;
import com.midea.ai.air.view.ListViewForScrollView;
import com.midea.ai.air.view.MyTitleBar;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hww on 2016/3/24.
 */
public class MoreSettingMyMessageActivity extends BaseActivity implements View.OnClickListener {

    MyTitleBar myTitleBar;
    private TextView actionbar_left_tv;
    private ListViewForScrollView mListView;
    private List<MoreMyMessageItem> mList_item = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_moresettingmymessage);

        init();
    }

    private RelativeLayout bar_Rl;

    private void init() {
        bar_Rl = (RelativeLayout) findViewById(R.id.bar_parent_rl);
        ViewGroup.LayoutParams LP = bar_Rl.getLayoutParams();
        LP.height = Constant.getTopMargin() + getResources().getDimensionPixelSize(R.dimen.height_44dp);
        bar_Rl.setLayoutParams(LP);

        myTitleBar = new MyTitleBar(this);
        myTitleBar.setActionBar_center(R.string.more_setting_my_message);
        myTitleBar.setActioBar_left(true, R.drawable.register_titler_left, R.string.nav_bar_more);
        myTitleBar.setActionBar_right(false, 0);

        actionbar_left_tv = (TextView) findViewById(R.id.actionbar_tv_left);
        actionbar_left_tv.setTextColor(getResources().getColor(R.color.electric_histogram));

        mListView = (ListViewForScrollView) findViewById(R.id.more_setting_my_message_listView);

        mList_item.add(new MoreMyMessageItem(R.drawable.more_my_message_01, "美的商城活动", "双十一明星狂欢，送3千万优惠券，小米4直降500元···", "星期五"));
        mList_item.add(new MoreMyMessageItem(R.drawable.more_my_message_02, "新家庭成员", "xwwx已经接受你的邀请", "15/10/30"));
        mList_item.add(new MoreMyMessageItem(R.drawable.more_my_message_03, "积分兑换活动", "新一轮抢净化器", "15/10/29"));
        mList_item.add(new MoreMyMessageItem(R.drawable.more_my_message_04, "用电限额", "您这个月的用电限额已经超出限额90%", "15/10/15"));
        mList_item.add(new MoreMyMessageItem(R.drawable.more_my_message_05, "定时体检", "定时体检已经触发，你的得得分是91分", "15/10/14"));
        mList_item.add(new MoreMyMessageItem(R.drawable.more_my_message_06, "定位开关", "定位开关已经触发，家电已经开启", "15/10/14"));
        mList_item.add(new MoreMyMessageItem(R.drawable.more_my_message_07, "智能联动", "智能联动已被触发，家电已近关闭", "15/10/09"));

        mListView.setAdapter(new MoreMyMessageAdapter(MoreSettingMyMessageActivity.this, mList_item));

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:

                        break;
                    case 1:

                        break;
                    case 2:

                        break;
                    case 3:
                        startActivity(new Intent(MoreSettingMyMessageActivity.this, MoreSettingElectricityReport.class));
                        break;
                    case 4:
                        //智能体检
                        startActivity(new Intent(MoreSettingMyMessageActivity.this, MoreSettingCheckbrainpower.class));
                        break;
                    case 5:
                        //开关日志
                        startActivity(new Intent(MoreSettingMyMessageActivity.this, MoreSettingLocationOnOffLogging.class));
                        break;
                    case 6:
                        //联动日志
                        startActivity(new Intent(MoreSettingMyMessageActivity.this, MoreSettingBrainpowerLogging.class));
                        break;
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.actionbar_left_relativeLayout:

                this.finish();
                break;
        }
    }


    private Dialog delete_Dialog;

    private void create_Delete_Logging_Dialog() {
        View view_delete_logging = LayoutInflater.from(MoreSettingMyMessageActivity.this)
                .inflate(R.layout.dialog_delete_logging_item, null);
        delete_Dialog = new Dialog(MoreSettingMyMessageActivity.this, R.style.my_activate_dialog);
        delete_Dialog.setCancelable(true);
        delete_Dialog.setCanceledOnTouchOutside(false);
        delete_Dialog.setContentView(view_delete_logging);
        TextView dialog_cancel = (TextView) view_delete_logging.findViewById(R.id.dialog_delete_logging_item_cancel);
        TextView dialog_confirm = (TextView) view_delete_logging.findViewById(R.id.dialog_delete_logging_item_confirm);
        dialog_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (delete_Dialog != null && delete_Dialog.isShowing()) {
                    delete_Dialog.dismiss();
                }
            }
        });
        dialog_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (delete_Dialog != null && delete_Dialog.isShowing()) {
                    delete_Dialog.dismiss();
                }
            }
        });
    }

}
